Support to build Python module without pkg-config
authorKentaro Hayashi <kenhys@xdump.org>
Fri, 5 Sep 2025 11:08:19 +0000 (20:08 +0900)
committerKentaro Hayashi <kenhys@xdump.org>
Fri, 5 Sep 2025 11:02:14 +0000 (20:02 +0900)
Gbp-Pq: Name support-python-module-in-place.patch

python/setup.py

index da68e71b9ce1627c2f5a18f8e56bb1e0cf39d841..84f5e926a96de051a49b98ad3852785c179dc5f1 100755 (executable)
@@ -85,15 +85,21 @@ class build_ext(_build_ext):
   """Override build_extension to run cmake."""
 
   def build_extension(self, ext):
-    cflags, libs = get_cflags_and_libs('../build/root')
-
-    if len(libs) == 0:
-      if is_sentencepiece_installed():
-        cflags = cflags + run_pkg_config('cflags')
-        libs = run_pkg_config('libs')
-      else:
-        subprocess.check_call(['./build_bundled.sh', __version__])
-        cflags, libs = get_cflags_and_libs('./build/root')
+    # cflags, libs = get_cflags_and_libs('../build/root')
+    # if len(libs) == 0:
+    #   cflags, libs = get_cflags_and_libs('./bundled/root')
+
+    # if len(libs) == 0:
+    #   if is_sentencepiece_installed():
+    #     cflags = cflags + run_pkg_config('cflags')
+    #     libs = run_pkg_config('libs')
+    #   else:
+    #     subprocess.check_call(['./build_bundled.sh', __version__])
+    #     cflags, libs = get_cflags_and_libs('./bundled/root')
+    cflags = ['-I../src']
+    cmd = "dpkg-architecture -q DEB_BUILD_GNU_TYPE"
+    arch = subprocess.check_output(cmd, shell=True).decode("utf-8").strip().split()[0]
+    libs = ["-L../obj-%s/src" % arch, "-lsentencepiece", "-lsentencepiece_train"]
 
     # Fix compile on some versions of Mac OSX
     # See: https://github.com/neulab/xnmt/issues/199